<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #app {
      width: 300px;
      height: 300px;
      margin: 50px;
    }
  </style>
</head>
<body>
  <a href="/boxA">boxA</a>
  <a href="/boxB">boxB</a>
  <a href="/boxC">boxC</a>

  <div id="app"></div>

  <script>
    const routes = [
      {
        path: "/boxA",
        element: "<span>我是boxA</span>"
      },
      {
        path: "/boxB",
        element: "<span>我是boxB</span>"
      },
      {
        path: "/boxC",
        element: "<span>我是boxC</span>"
      }
    ]
    
    const aNodes = document.querySelectorAll("a")

    aNodes.forEach(item => {
      item.addEventListener("click", e => {
        e.preventDefault()
        history.pushState(null, null, e.target.href)
        const targetRoute = routes.find(item => item.path === e.target.pathname)
        document.getElementById("app").innerHTML = targetRoute.element
      })
    })
  </script>
</body>
</html>